//
//  LGCloseAppointView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/21.
//

#import "LGCloseAppointView.h"

@interface LGCloseAppointView()

/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIButton *openButton;
/**   */
@property (nonatomic , strong)UIButton *closeButton;
/**   */
@property (nonatomic , strong)UIButton *cancelButton;
/**   */
@property (nonatomic , strong)UIView *lineView1;
/**   */
@property (nonatomic , strong)UIView *lineView2;

@end

@implementation LGCloseAppointView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0];
        [self addSubview:self.baseView];
        [self.baseView addSubview:self.openButton];
        [self.baseView addSubview:self.closeButton];
        [self.baseView addSubview:self.cancelButton];
        [self.baseView addSubview:self.lineView1];
        [self.baseView addSubview:self.lineView2];
        [UIView animateWithDuration:0.4 animations:^{
            self.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0.5];
            self.baseView.frame = CGRectMake(0, Screen_H-viewPix(189), Screen_W, viewPix(200));
        }];
    }
    return self;
}

-(void)buttonTouchAction:(UIButton *)sender{
    if(sender == self.openButton){
        if(self.appointAction){
            self.appointAction(@"1");
        }
    }else if (sender == self.closeButton){
        if(self.appointAction){
            self.appointAction(@"0");
        }
    }
    [UIView animateWithDuration:0.4 animations:^{
        self.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0];
        self.baseView.frame = CGRectMake(0, Screen_H, Screen_W, viewPix(200));
    }completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}



-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_H, Screen_W, viewPix(200))];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 10;
    }
    return _baseView;
}

-(UIButton *)openButton{
    if(!_openButton){
        _openButton = [UIButton buttonWithTitle:@"接诊" titleFont:LGFont(16) textColor:@"#2B2A37" imageName:@""];
        _openButton.frame = CGRectMake(0, 0, Screen_W, viewPix(64));
        [_openButton addTarget:self action:@selector(buttonTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _openButton;
}

-(UIButton *)closeButton{
    if(!_closeButton){
        _closeButton = [UIButton buttonWithTitle:@"停诊" titleFont:LGFont(16) textColor:@"#2B2A37" imageName:@""];
        _closeButton.frame = CGRectMake(0, kMaxY(self.openButton.frame), Screen_W, viewPix(64));
        [_closeButton addTarget:self action:@selector(buttonTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeButton;
}

-(UIButton *)cancelButton{
    if(!_cancelButton){
        _cancelButton = [UIButton buttonWithTitle:@"取消" titleFont:LGFont(16) textColor:@"#2B2A37" imageName:@""];
        _cancelButton.frame = CGRectMake(0, kMaxY(self.closeButton.frame)+viewPix(10), Screen_W, viewPix(50));
        [_cancelButton addTarget:self action:@selector(buttonTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelButton;
}

-(UIView *)lineView1{
    if(!_lineView1){
        _lineView1 = [[UIView alloc]initWithFrame:CGRectMake(0, kMaxY(self.openButton.frame), Screen_W, 1)];
        _lineView1.backgroundColor = [UIColor colorWithString:@"#FAFAFA"];
    }
    return _lineView1;
}

-(UIView *)lineView2{
    if(!_lineView2){
        _lineView2 = [[UIView alloc]initWithFrame:CGRectMake(0, kMaxY(self.closeButton.frame), Screen_W, viewPix(10))];
        _lineView2.backgroundColor = [UIColor colorWithString:@"#FAFAFA"];
    }
    return _lineView2;
}

@end
